<?php

// Begin the session
session_start();

$name = $_GET['name'];
$len = $_GET['len'];
if ($len < 3) {
	$len = 3;
}

// If the session is not present, set the variable to an error message
$possible="ABCDEFGHIJ3456KLMNOPQRST012679";
while(strlen($str)<$len)
{
	$char = substr($possible,(rand()%(strlen($possible))),1);
	$str.= $char;
}
$str = str_replace(" ", '', $str);
$_SESSION["{$name}_capcha_string"] = $str;

//if(!isset($_SESSION["{$name}_capcha_string"]))
//	$str = 'ERROR!';
//// Else if it is present, set the variable to the session contents
//else
//	$str = $_SESSION["{$name}_capcha_string"];

// Set the content type
//header('Content-type: image/png');
header('Cache-control: no-cache');

// Create an image from button.png
$image = imagecreatefromgif('capcha.gif');

// Set the font colour
$colour = imagecolorallocate($image, 0, 0, 0);

// Set the font
$font = '../fonts/Anorexia.ttf';

// Set a random integer for the rotation between -15 and 15 degrees
$rotate = rand(-5, 5);

// Create an image using our original image and adding the detail
imagettftext($image, 16, $rotate, 18, 30, $colour, $font, $str);

// Output the image as a png
imagepng($image);

?>